/**
 * 
 */
package com.glela.common.util;

import java.util.Set;

import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;

/**
 * @author liujie
 *
 * 数据验证器
 */
public class ValidatorUtil {
	private static class ValidatorHolder{
		static Validator validator = Validation.buildDefaultValidatorFactory().getValidator(); 
	}
	
	private ValidatorUtil(){};
	
	public static String validate(Object obj){
		StringBuffer buf = new StringBuffer(); 
		Set<ConstraintViolation<Object>> constraintViolations = ValidatorHolder.validator.validate(obj);
		for(@SuppressWarnings("rawtypes") ConstraintViolation err : constraintViolations) {  
			buf.append(err.getMessage()+"\n");
		}  
		
		return buf.toString();
	}
}
